package cn.iocoder.yudao.module.member.api.images;

import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.api.images.uto.ImagesDOVO;
import cn.iocoder.yudao.module.member.convert.images.ImagesConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.images.ImagesDO;
import cn.iocoder.yudao.module.member.dal.mysql.images.ImagesMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ImagesMapperApiImpl implements ImagesMapperApi{

    @Resource
    private ImagesMapper imagesMapper;

    @Override
    public void updateImagesList(List<ImagesDOVO> list) {

        imagesMapper.updateBatch(ImagesConvert.INSTANCE.convertList6(list));
    }

    @Override
    public void insertImagsList(List<ImagesDOVO> list) {
        imagesMapper.insertBatch(ImagesConvert.INSTANCE.convertList6(list));
    }

    @Override
    public String selectByCrmMemberUserId(Long crmMemberUserId) {

        LambdaQueryWrapperX<ImagesDO> wrapperX = new LambdaQueryWrapperX<>();
        wrapperX.eq(ImagesDO ::getThirdId, crmMemberUserId);
        List<ImagesDO> imagesDO = imagesMapper.selectList(wrapperX);
        if (CollectionUtils.isEmpty(imagesDO)){
            return null;
        }
        List<String> collect = imagesDO.stream().map(ImagesDO::getImageLink).collect(Collectors.toList());

        return String.join(",", collect);
    }
}
